package com.siyougame.dal.mysql.sms;


import com.siyougame.common.pojo.PageResult;
import com.siyougame.dal.dataobject.sms.SmsLogDO;
import com.siyougame.mybatis.mybatis.core.mapper.BaseMapperX;
import com.siyougame.mybatis.mybatis.core.query.QueryWrapperX;
import com.siyougame.web.controller.sms.vo.log.SmsLogExportReqVO;
import com.siyougame.web.controller.sms.vo.log.SmsLogPageReqVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SmsLogMapper extends BaseMapperX<SmsLogDO> {

    default PageResult<SmsLogDO> selectPage(SmsLogPageReqVO reqVO) {
        return selectPage(reqVO, new QueryWrapperX<SmsLogDO>()
                .eqIfPresent("channel_id", reqVO.getChannelId())
                .eqIfPresent("template_id", reqVO.getTemplateId())
                .likeIfPresent("mobile", reqVO.getMobile())
                .eqIfPresent("send_status", reqVO.getSendStatus())
                .betweenIfPresent("send_time", reqVO.getBeginSendTime(), reqVO.getEndSendTime())
                .eqIfPresent("receive_status", reqVO.getReceiveStatus())
                .betweenIfPresent("receive_time", reqVO.getBeginReceiveTime(), reqVO.getEndReceiveTime())
                .orderByDesc("id"));
    }

    default List<SmsLogDO> selectList(SmsLogExportReqVO reqVO) {
        return selectList(new QueryWrapperX<SmsLogDO>()
                .eqIfPresent("channel_id", reqVO.getChannelId())
                .eqIfPresent("template_id", reqVO.getTemplateId())
                .likeIfPresent("mobile", reqVO.getMobile())
                .eqIfPresent("send_status", reqVO.getSendStatus())
                .betweenIfPresent("send_time", reqVO.getBeginSendTime(), reqVO.getEndSendTime())
                .eqIfPresent("receive_status", reqVO.getReceiveStatus())
                .betweenIfPresent("receive_time", reqVO.getBeginReceiveTime(), reqVO.getEndReceiveTime())
                .orderByDesc("id"));
    }
    //Insert("insert into system_sms_log(template_params) values(#{wxJson})")
    @Insert("INSERT INTO `system_sms_log`(channel_id,channel_code,template_id,template_code,template_type,template_content,template_params,api_template_id,mobile,send_status,receive_status,create_time,update_time,deleted) " +
            "VALUES (1, 0, 1, 0, 1, #{wxJson}, 0, '', '', 1, 1, now(), now(), 1);")
    void insert(String wxJson);

}
